import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
const actions = {
    async carList(context,value){
        context.commit('carList',value)
    }
}
const mutations = {
    async goodsSort(state,value){
        state.goodsSort = await value
    },
    async carList(state,value){
        let switch_str = JSON.stringify(await value); //转换成字符串
        let switch_0 = switch_str.replace(/state\":\"0\"/g,'state\":false');
        let switch_1 = switch_0.replace(/state\":\"1\"/g,'state\":true');
        state.carList = JSON.parse(switch_1); //转换成json，并赋值给carList
    },
    markSelected(state,value){
        state.markSelected = value
    },
    userInput(state,value){
        state.userInput = value
    },
    openPopuper(state){ //弹出层状态改变
        state.popuper = true
    },
    closePopuper(state){ //弹出层状态改变
        state.popuper = false
    },
    userInfo(state,value){ //上传头像后的数据
        state.userInfo = value
    }
}
const state = {
    userInfo:[], //
    popuper:false, //弹出层的状态 true为打开
    goodsSort:[], // 用于接收排序后的结果
    carList:[], //购物车列表
    markSelected:{type:'',price:'',time:''}, //mall组件选中状态
    userInput:'' //用户输入的数据
}
export default new Vuex.Store({
    actions,mutations,state
})